﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace Mes.Application.DTO.Results.WorkOrders
{
    public class EntJobsResult
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Wo_Id { get; set; } = string.Empty;

        /// <summary>
        /// 工单描述
        /// </summary>
        public string? Wo_Desc { get; set; }

        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;

        /// <summary>
        /// 作业描述
        /// </summary>
        public string? Job_Desc { get; set; }

        /// <summary>
        /// 物料ID
        /// </summary>
        public int Item_Id { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string Item_Name { get; set; } = string.Empty;

        /// <summary>
        /// 开工数量
        /// </summary>
        public double Qty_At_Start { get; set; }

        /// <summary>
        /// 所需产量
        /// </summary>
        public double Qty_Reqd { get; set; }

        /// <summary>
        /// 作业状态
        /// </summary>
        public int State_Cd { get; set; }

        /// <summary>
        /// 作业描述
        /// </summary>
        public string State_Desc { get; set; }

        /// <summary>
        /// 所需完工日期/时间
        /// </summary>
        public DateTime? Req_Finish_Time_Local { get; set; }

        /// <summary>
        /// 可调度
        /// </summary>
        public int Init_Sched_Ent_Id { get; set; }

        /// <summary>
        /// 可调度名称
        /// </summary>
        public string Init_Sched_Ent_Name { get; set; } = string.Empty;

        /// <summary>
        /// 良品数
        /// </summary>
        public double Qty_Prod { get; set; }

        /// <summary>
        /// 次品数
        /// </summary>
        public double Qty_Rejected { get; set; }
    }

    public class RunningJobProdBOMStepResult
    {
        /// <summary>
        /// 良品产量列表
        /// </summary>
        public IList<ItemProdResult> ItemProdResults { get; set; } = new List<ItemProdResult>();

        /// <summary>
        /// 物料清单
        /// </summary>
        public IList<RunningJobBomResult> RunningJobBomResults { get; set; } = new List<RunningJobBomResult>();

        /// <summary>
        /// 工步组列表
        /// </summary>
        public IList<RunningJobStepGrpResult> RunningJobStepGrpResults { get; set; }=new List<RunningJobStepGrpResult>();
    }

    public class ItemProdResult
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime Last_Edit_At { get; set; }

        /// <summary>
        /// 产量
        /// </summary>
        public double Qty_Prod { get; set; }

        /// <summary>
        /// 物料编号
        /// </summary>
        public int Item_Id { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string Item_Name { get; set; }=string.Empty;

        /// <summary>
        /// 目标存储位置Id
        /// </summary>
        public int? To_Ent_Id { get; set; }

        /// <summary>
        /// 目标存储位置名称
        /// </summary>
        public string To_Ent_Name { get; set; } = string.Empty;

        /// <summary>
        /// 是否是良品
        /// </summary>
        public bool Good_Prod { get; set; }
    }

    public class RunningJobBomResult
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Wo_Id { get; set; } = string.Empty;

        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;

        /// <summary>
        /// 物料编号
        /// </summary>
        public int Item_Id { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string Item_Name { get; set; } = string.Empty;

        /// <summary>
        /// 成品数量
        /// </summary>
        public double Qty_Per_Parent_Item { get; set; }

        /// <summary>
        /// 所需产量
        /// 如果job.Qty_Prod<=job.Qty_At_Start,则所需产量=job.Qty_At_Start*Qty_Per_Parent_Item
        /// 如果job.Qty_Prod>job.Qty_At_Start,则所需产量=job.Qty_Prod*Qty_Per_Parent_Item
        /// </summary>
        public double Reqd_Qty_Prod { get; set; }

        /// <summary>
        /// 消耗量(item_cons.Qty_Cons)
        /// </summary>
        public double? Qty_Cons { get; set; }

        /// <summary>
        /// 投产数量（job.Qty_At_Start）
        /// </summary>
        public double ProductionQuantity { get; set; }
    }

    public class RunningJobStepGrpResult
    {
        public int Step_Grp_Id { get; set; } = 0;

        public string Step_Grp_Desc { get; set; } = string.Empty;

        public int Step_Grp_Seq { get; set; } = 0;

        public IList<RunningJobStepResult> RunningJobStepResults { get; set; } = new List<RunningJobStepResult>();
    }

    public class RunningJobStepResult
    {
        /// <summary>
        /// 工步编号
        /// </summary>
        public int Step_No { get; set; }

        /// <summary>
        /// 工步描述
        /// </summary>
        public string Step_Desc { get; set; } = string.Empty;

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? Act_Start_Time_Local { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? Act_Finish_Time_Local { get; set; }

        /// <summary>
        /// 状态ID
        /// </summary>
        public int State_Cd { get; set; }

        /// <summary>
        /// 状态描述
        /// </summary>
        public string State_Desc { get; set; }
    }
}
